package com.apple1.blogweb.controllers;

import java.util.Properties;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.apple1.blogentity.User;
import com.apple1.blogentity.form.UserForm;
import com.apple1.blogservices.UserService;
import com.apple1.commonutil.common.ServerResponse;

/**
 *
 * @author huangliwei
 * @date   2019年1月20日
 */
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;

	/**
	 * 用户注册
	 * @param model
	 * @return
	 */
	@PostMapping("/register")
	public Object register(UserForm model, @RequestParam("file") MultipartFile file, HttpServletRequest request) {
		return userService.register(model, file, request);
	}
	
	/**
	 * 未登录的跳转
	 * @return
	 */
	@RequestMapping(value = "/unauth")
    public Object unauth() {
        Properties properties = new Properties();
        return ServerResponse.failBack(properties, "未登录");
    }
	
	@RequestMapping(value = "/login")
	public Object login(User user, HttpServletRequest request) {
		return userService.login(user, request);
	}
	
	@RequestMapping(value = "/getUserInfo")
	public Object getUserInfo(String userName) {
		return userService.getUserInfo(userName);
	}
	
	@RequestMapping(value = "/getUserInfoList")
	public Object getUserInfoList(int pageNum, int pageCount) {
		return userService.getUserInfoList(pageNum, pageCount);
	}
	
	@RequestMapping(value = "/getEmailVaildCode")
	public Object getEmailVaildCode(String email, HttpServletRequest request) {
		return userService.getEmailVaildCode(email, request);
	}
	
	
	
	
}
